

#import "FAMGoalViewController.h"

@interface FAMGoalViewController ()
@property (weak, nonatomic) IBOutlet UIView *FAMPageBackView;
@property (weak, nonatomic) IBOutlet UIButton *FAMLoseButton;
@property (weak, nonatomic) IBOutlet UIButton *FAMGainButton;
@property (weak, nonatomic) IBOutlet UIButton *FAMMaintainButton;
@property (weak, nonatomic) IBOutlet UILabel *FAMHudMessageLabel;

@end

@implementation FAMGoalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.fd_prefersNavigationBarHidden = YES;
    [self FAM_showUi];
}

- (void)FAM_showUi{
    self.FAMPageBackView.layer.shadowColor = kCustom0xColor(0x000000, 1.0).CGColor;
    self.FAMPageBackView.layer.shadowOpacity = 0.15;
    self.FAMPageBackView.layer.shadowRadius = 1.5;
    self.FAMPageBackView.layer.shadowOffset = CGSizeMake(2, 2);
    
}
- (IBAction)FAM_backButtonClick:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)FAM_nextButtonClick:(UIButton *)sender {
    WeakSelf(self);
    if (self.FAMLoseButton.isSelected || self.FAMGainButton.isSelected || self.FAMMaintainButton.isSelected) {
        [self showHudInKeyWindowWithHint:@""];
        [FAMHttpTool FAM_PostFoodmateUserdataWithParameters:[NSMutableDictionary dictionaryWithDictionary:@{@"data":self.FAMFoodmateUserdataDictionary}] success:^(FAMFoodmateUserdataModel * model, NSString * msg) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf hideHudKeyWindow];
                FAMBMIViewController *vc = [FAMBMIViewController new];
                vc.FAMFoodmateUserdataDictionary = weakSelf.FAMFoodmateUserdataDictionary;
                [weakSelf.navigationController pushViewController:vc animated:YES];
            });
        } failure:^(NSString * _Nonnull errorInfo) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf hideHudKeyWindow];
                [weakSelf showHint:errorInfo];
            });
        }];
    }else{
//        [self showHint:@"Please select your goal"];
        [self.FAMHudMessageLabel setHidden:NO];
        [self performSelector:@selector(FAM_setHud) withObject:nil afterDelay:3];
    }
}
- (void)FAM_setHud{
    [self.FAMHudMessageLabel setHidden:YES];
}
- (IBAction)FAM_loseButtonClick:(UIButton *)sender {
    [self FAM_sender:sender otherOneButton:self.FAMGainButton otherTwoButton:self.FAMMaintainButton];
    [self.FAMFoodmateUserdataDictionary setValue:@"1" forKey:@"target_type"];
}
- (IBAction)FAM_gainButtonClick:(UIButton *)sender {
    [self FAM_sender:sender otherOneButton:self.FAMLoseButton otherTwoButton:self.FAMMaintainButton];
    [self.FAMFoodmateUserdataDictionary setValue:@"2" forKey:@"target_type"];
}
- (IBAction)FAM_maintainButtonClick:(UIButton *)sender {
    [self FAM_sender:sender otherOneButton:self.FAMLoseButton otherTwoButton:self.FAMGainButton];
    [self.FAMFoodmateUserdataDictionary setValue:@"3" forKey:@"target_type"];
}
- (void)FAM_sender:(UIButton *)sender otherOneButton:(UIButton *)buttonOne otherTwoButton:(UIButton *)buttonTwo{
    [sender setSelected:YES];
    [buttonOne setSelected:NO];
    [buttonTwo setSelected:NO];
    sender.layer.borderColor = kBlackColor.CGColor;
    sender.layer.borderWidth = 2;
    buttonOne.layer.borderColor = kWhiteColor.CGColor;
    buttonOne.layer.borderWidth = 2;
    buttonTwo.layer.borderColor = kWhiteColor.CGColor;
    buttonTwo.layer.borderWidth = 2;
    
}



@end
